<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="C" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>图书管理系统</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/index.css" charset="utf-8">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
      integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <link rel="stylesheet" href="static/css/base.css">
</head>
<body>

<div class="container">
    <h2 align="center">借阅信息管理</h2>
    <h5 align="center">${sessionScope.msg}</h5>
    <button class="btn btn-primary" style="float: right; margin-right: 20px;" onclick="ReturnBack()">注销</button>
    <div class="search">
        <label>
            <input type="text" placeholder="输入你想搜索的书籍" id="search"/>
        </label>
        <button onclick="search()" class="glyphicon glyphicon-search">搜索</button>
        <div id="productAutoComplete">
            <ul id="productAutoList">
            </ul>
        </div>
    </div>
    <div class="bookList">
        <div class="col-md-12 column">
            <div class="panel-heading">
                <button class="btn btn-primary" onclick="toAddBorrowInfo()">添加</button>
                <button class="btn btn-primary" onclick="refresh()">刷新</button>
                <button class="btn btn-primary" id="bookinfo">图书信息</button>
            </div>

            <table class="table table-hover table-striped">
                <thead>

                <tr align="right">
                    <th width="50px">序号</th>
                    <th width="350px">书名</th>
                    <th width="200px">读者</th>
                    <th width="120px">借阅日期</th>
                    <th width="120px">归还日期</th>
                    <th>是否归还</th>
                    <th width="150px">操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach items="${sessionScope.borrowInfoList}" var="borrowInfo" varStatus="status">
                    <tr>
                        <td>${status.count + (sessionScope.borrowInfocurrent-1)*10}</td>
                        <td>${borrowInfo.bookName}</td>
                        <td>${borrowInfo.reader}</td>
                        <td>${borrowInfo.borrowDate}</td>
                        <td>${borrowInfo.returnDate}</td>
                        <c:if test="${borrowInfo.isReturn==1}">
                            <td>是</td>
                        </c:if>
                        <c:if test="${borrowInfo.isReturn==0}">
                            <c:if test="${borrowInfo.shouldReturn==true}">
                                <td font-color="red">否</td>
                            </c:if>
                            <c:if test="${borrowInfo.shouldReturn==false}">
                                <td>否</td>
                            </c:if>
                        </c:if>
                        <td>
                            <a onclick="return foo();" href="<%=request.getContextPath()%>/DeleteBorrowInfoServlet?borrowId=${borrowInfo.borrowId}">删除</a>
                            |
                            <a href="<%=request.getContextPath()%>/GetOneBorrowInfoServlet?borrowId=${borrowInfo.borrowId}">编辑</a>
<%--                            <a href="<%=request.getContextPath()%>/BorrowInfoDetailServlet?borrowId=${borrowInfo.borrowId}">查看详情</a>--%>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>

        </div>
        <nav aria-label="Page navigation">
            <ul class="pagination right">
                <li>
                    <a href="<%=request.getContextPath()%>/GetBorrowInfoServlet?borrowInfocurrent=${sessionScope.borrowInfocurrent > 1 ? sessionScope.borrowInfocurrent-1:sessionScope.borrowInfocurrent}"
                       aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
                <c:forEach begin="1" end="${sessionScope.borrowInfopage}" var="i">
                    <c:if test="${i==sessionScope.borrowInfocurrent}">
                        <li class="active"><a href="<%=request.getContextPath()%>/GetBorrowInfoServlet?borrowInfocurrent=${i}">${i}</a></li>
                    </c:if>
                    <c:if test="${i!=sessionScope.borrowInfocurrent}">
                        <li><a href="<%=request.getContextPath()%>/GetBorrowInfoServlet?borrowInfocurrent=${i}">${i}</a></li>
                    </c:if>
                </c:forEach>
                <li>
                    <a href="<%=request.getContextPath()%>/GetBorrowInfoServlet?borrowInfocurrent=${sessionScope.borrowInfocurrent < sessionScope.borrowInfopage ? sessionScope.borrowInfocurrent+1:sessionScope.borrowInfocurrent}"
                       aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            </ul>
        </nav>
    </div>
</div>
<script type="text/javascript">
    function refresh() {
        window.location = "<%=request.getContextPath()%>/GetBorrowInfoServlet?borrowInfocurrent=1&size=10"
    }

    function toAddBorrowInfo() {
        window.location = "<%=request.getContextPath()%>/addBorrowInfo.jsp";
    }

    function search() {
        s = document.getElementById("search")
        window.location = "<%=request.getContextPath()%>/GetBorrowInfoServlet?borrowInfocurrent=1&size=10&key=" + s.value
    }

    function foo() {
        return confirm("确定要删除吗？");
    }
    function ReturnBack(){
        window.location.href = '<%=request.getContextPath()%>/LogoutServlet';
    }
    var input = document.getElementById("search")
    input.addEventListener("keyup", function (event) {
        event.preventDefault()
        if (event.keyCode === 13 && input.value !== "") {
            search()
        }
    })
</script>
<script type="text/javascript" src="js/borrowInfo.js"></script>
</body>
</html>
